<template>
	<view style="background-color: #FFFFFF;">
		<uni-segmented-control :current="current" 
		:values="items" @clickItem="onClickItem" 
		style-type="text" active-color="#71d5a1"></uni-segmented-control>
		<view class="content">
			<view v-show="current === 0">

				<view v-for="item in disscussions">
					<u-row style="margin-top: 10rpx;" >
						<u-col span="12">
							<!-- 楼主信息 -->
							<view @click="showitem(item.id)">
								<!-- 帖子创建人信息 -->
							<u-row>
								<u-col span="1"><text style="color: #FFFFFF;">1</text></u-col>
								<u-col span="2">
									<u-avatar :src="headimg"></u-avatar>
								</u-col>
								<u-col span="7">
									<view style="font-size: 35rpx;font-weight: 700">{{item.createdBy}}</view>
									<view style="font-size: 23rpx; color: #808080;">创建于：{{item.createDate}}</view>
								</u-col>
								<u-col span="1"><text style="color: #FFFFFF;">1</text></u-col>
							</u-row>
							
							<!-- 标题 -->
							<u-row>
								<u-col span="1"><text style="color: #FFFFFF;">1</text></u-col>
								<u-col span="10" class="u-line-1">
									<text style="font-weight: 700;font-size: 37rpx;">{{item.title}}</text>
								</u-col>
								<u-col span="1"><text style="color: #FFFFFF;">1</text></u-col>
							</u-row>
							
							<!-- 内容摘要 -->
							<u-row>
								<u-col span="1"><text style="color: #FFFFFF;">1</text></u-col>
								<u-col span="10" >
									<text class="u-line-3">{{item.content}}</text>
								</u-col>
								<u-col span="1"><text style="color: #FFFFFF;">1</text></u-col>
							</u-row>
							</view>

							<!-- 点赞评论信息等 -->
							<u-divider border-color="#999999" :use-slot="false" :half-width="300" height="30"></u-divider>
							<u-row>
								<u-col span="4" style="text-align: center;">
									<span >
										<u-icon name="share"></u-icon><text>{{item.forward}}</text>
									</span>
								</u-col>
								<u-col span="4" style="text-align: center;">
									<span   >
										<u-icon name="chat"></u-icon><text>{{item.comments}}</text>
									</span>
								</u-col>
								<u-col span="4" style="text-align: center;">
									<span >
										<u-icon name="thumb-up"  ></u-icon><text >{{item.likes}}</text>
									</span>
								</u-col >
							</u-row >
							<u-divider border-color="#f4f4f5" :use-slot="false" :half-width="750" height="20" bg-color="#f4f4f5">
							</u-divider>
						</u-col>
					</u-row>
					<u-divider border-color="#f4f4f5" :use-slot="false" :half-width="750" height="20" bg-color="#f4f4f5"></u-divider>
				</view>
			</view>
			<view v-show="current === 1">
				<view v-for="item in comments">
					<u-row style="margin-top: 10rpx;" >
						<u-col span="1"></u-col>
						<u-col span="10"  style="background-color:#F4F4F5;border-radius:30 ;">
							<u-row>
								<u-col span="1"><text style="color: #FFFFFF;"></text></u-col>
								<u-col span="2">
									<u-avatar :src="headimg"></u-avatar>
								</u-col>
								<u-col span="7">
									<view style="font-size: 35rpx;font-weight: 700">{{item.createdBy}}</view>
									<view style="font-size: 23rpx; color: #808080;">创建于：{{item.createDate}}</view>
								</u-col>
								<u-col span="1"><text style="color: #FFFFFF;"></text></u-col>
							</u-row>
							<u-row>
								<u-col span="1"><text style="color: #FFFFFF;"></text></u-col>
								<u-col span="10" >
									回复：<text class="u-line-3">{{item.content}}</text>
									<u-divider border-color="#FFFFFF"  :use-slot="false" :half-width="750" height="3"></u-divider>
								</u-col>
								<u-col span="1"><text style="color: #FFFFFF;"></text></u-col>
							</u-row>
							<u-row>
								<u-col span="1"><text style="color: #FFFFFF;"></text></u-col>
								<u-col span="10" >
									原贴：{{item.discussion.title}}
								</u-col>
								<u-col span="1"><text style="color: #FFFFFF;"></text></u-col>
							</u-row>
						</u-col>
						<u-col span="1"></u-col>
					</u-row>
				</view>
			</view>
			
		</view>
	</view>
</template>

<script>

	import uniSegmentedControl from "@/components/uni-segmented-control/uni-segmented-control.vue"
	export default {
		comments: {
			uniSegmentedControl
		},
		data() {
			return {
				items: ['我的发帖', '我的回复'],
				current: 0,
				comments:[],
				disscussions:[],
				headimg:this.$store.state.userInfo.headImg
			};
		},
		methods: {
			onClickItem(e) {
				if (this.current !== e.currentIndex) {
					this.current = e.currentIndex;
				}
			},
			showitem(id){
				uni.navigateTo({
					url: "dessionitem?id=" + id,
				})
			},
			getComments(){
				// console.log("开始获取个人中心评论数据")
				uni.request({
					url:this.baseurl+"cComment/comment/"+this.$store.state.userInfo.name,
					success: (res) => {
						// console.log(res.data);
						var result = res.data;
						if(result.code==200){
							this.comments=result.result.comments;
							console.log(this.comments)
						}
					}
				})
			},
			getDiscussion(){
				// console.log("开始获取个人中心发帖数据");
				uni.request({
					url:this.baseurl+"cDiscussion/disscussion/"+this.$store.state.userInfo.name,
					success: (res) => {
						// console.log(res.data);
						var result = res.data;
						if(result.code==200){
							this.disscussions=result.result.discussion;
							console.log(this.disscussions);
						}
					}
				})
			}
			
		},
		onLoad: function(option) {
			// console.log(this.$store.state.userInfo);
			this.getComments();
			this.getDiscussion();
		},
		onPullDownRefresh:function(){
			this.getComments();
			this.getDiscussion();
		}
	};
</script>
